﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using DAL;

public partial class admin_FriendLinksMod : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["LoginUser"] == null)
        {
            Response.Write(" <script> top.location.href= 'login.aspx'; </script> ");
            return;
        }
        if (!IsPostBack)
        {
            LoadInfo();
        }
    }

    /// <summary>
    /// 加载信息
    /// </summary>
    protected void LoadInfo()
    {
        string id = Request.Params.Get("id");
        Links link = LinksDAL.Instance.SelectLinksInfoForId(id);
        if (link != null)
        {
            txtTitle.Text = link.Title;
            txtENTitle.Text = link.ENTitle;
            txtUrl.Text = link.Url;
            txtSort.Text = link.Sort.ToString();
            txtId.Text = link.Id.ToString();
        }
        
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Links user = new Links();
        user.Id = int.Parse(txtId.Text.Trim());
        user.Title = txtTitle.Text.Trim();
        user.ENTitle = txtENTitle.Text.Trim();
        user.Url = txtUrl.Text.Trim();
        user.Sort = txtSort.Text.Trim()==""?99:int.Parse(txtSort.Text.Trim());
        if (LinksDAL.Instance.UpdateLinks(user) > 0)
        {
            Alert("修改成功!");
            ExecuteScript("btnAdd();");
        }
        else
        {
            Alert("修改失败!");
        }


    }
}